package com.interview.javabase.thread;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @description:
 * @author: zhangshuguang@vichain.com
 * @date: 2019/06/14 13:49
 */
public class Demo7 {
    static volatile int x = 0, y = 0;
    static volatile int a = 0, b = 0;

    public static void main(String[] args) throws InterruptedException {

        for (int i = 0; i < 20000; i++) {
            Thread one = new Thread(new Runnable() {
                @Override
                public void run() {
                    a = 1;
                    x = b;
                }
            });

            Thread other = new Thread(new Runnable() {
                @Override
                public void run() {
                    b = 1;
                    y = a;
                }
            });
            one.start();other.start();
            one.join();other.join();
            System.out.println("(" + x + "," + y + ")");

              x = 0; y = 0;
              a = 0; b = 0;
        }

    }

}

class Test3 {
    int a = 0;

    boolean flag = false;

    public void m1() {
        a = 1;
        flag = true;
    }

    public void m2() {
        if (flag) {
            a = a + 5;
            System.out.println(" a = " + a);
        }
    }
}
